package my.fuelwallet.test;

import java.util.ArrayList;
import java.util.Scanner;

import my.fuelwallet.test.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.TableRow.LayoutParams;

public class ShowPrice extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		FuelPriceHandle fuelpriceDatabase = new FuelPriceHandle(this);
		fuelpriceDatabase.open();
		ArrayList<String> fuelnameList = (ArrayList<String>) fuelpriceDatabase
				.getFuelNameList();
		// fuelpriceDatabase.close();
		setContentView(R.layout.showprice);
		/* Find Tablelayout defined in main.xml */
		TableLayout tl = (TableLayout) findViewById(R.id.myTableLayout);
		TableRow rowTemp = (TableRow) findViewById(R.id.leadingrow);
		for (int i = 0; i < fuelnameList.size(); i++) {
			TableRow tr = new TableRow(this);
			tr.setLayoutParams(rowTemp.getLayoutParams());
			tr.setBackgroundDrawable(rowTemp.getBackground());
			FuelPrice fuelpriceTemp = fuelpriceDatabase
					.getFuelPrice(fuelnameList.get(i));
			Scanner fuelnameScanner = new Scanner(fuelpriceTemp.getfuelName());
			fuelnameScanner.useDelimiter("/");
			TextView brandView = new TextView(this);
			TextView productView = new TextView(this);
			TextView priceView = new TextView(this);
			brandView.setText(fuelnameScanner.next().trim());
			productView.setText(fuelnameScanner.next().trim());
			priceView.setText(fuelpriceTemp.getfuelPrice() + "");
			TextView brandTemp = (TextView) findViewById(R.id.brandColumn);
			TextView productTemp = (TextView) findViewById(R.id.productColumn);
			TextView priceTemp = (TextView) findViewById(R.id.priceColumn);
			brandView.setLayoutParams(brandTemp.getLayoutParams());
			productTemp.setLayoutParams(productTemp.getLayoutParams());
			priceView.setLayoutParams(priceTemp.getLayoutParams());
			brandView.setBackgroundDrawable(this.getResources().getDrawable(
					R.drawable.childcell_shape));
			productView.setBackgroundDrawable(this.getResources().getDrawable(
					R.drawable.childcell_shape));
			priceView.setBackgroundDrawable(this.getResources().getDrawable(
					R.drawable.childcell_shape));
			brandView.setGravity(Gravity.CENTER);
			productView.setGravity(Gravity.CENTER);
			priceView.setGravity(Gravity.CENTER);
			brandView.setTextColor(R.color.black);
			productView.setTextColor(R.color.black);
			priceView.setTextColor(R.color.black);
			
			tr.addView(brandView);
			tr.addView(productView);
			tr.addView(priceView);
			tl.addView(tr, new TableLayout.LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		}
		fuelpriceDatabase.close();
		/* Add row to TableLayout. */
	}
}